package models;

import java.util.*;
import javax.persistence.*;

import play.Logger;
import play.data.format.*;
import play.data.validation.*;

import controllers.LogSession;

public class Login {

	@Constraints.Required
	@Formats.NonEmpty
	public String username;

	@Constraints.Required
	public String password;

	public String redirect;
	
	public String lang;

	public String validate() {
		if(User.authenticate(username, password) == null) {
			return "login.error.invalidCredentials";
		}
		
		User user = User.findByUser(username);
		
		if(user.role==2 && LogSession.isUserAlreadyLogin(username))
			return "login.error.officerAlreadyLogin";			

		return null;
	}


}

